
using UnityEngine;


public enum E_MusicType
{

}

public enum E_SoundType
{
    PlayerCounterAttack = 0,
    PlayerPrimaryAttack = 2,
    BanKai = 3,
    Click = 7,
    FootStep = 14,
    grilSigh2 = 15,
    grilSigh = 17,
    ItemPickUp = 18,
    SkeleAttack = 24,
    RotateSword = 27,
    NormalSword = 28,
    WomanStruggle = 35
}

public class AudioManager : SingletonMono<AudioManager>,ISaveManager
{
    public AudioClip[] musics;
    public AudioClip[] sounds;
    public AudioSource currBgm;
    public AudioSource currSfx;
    private float musicValue;
    private float soundValue;

    public float MusicValue
    {
        get
        {
            return musicValue;
        }
        set
        {
            musicValue = value;
            currBgm.volume = value;
        }
    }
    public float SoundValue
    {
        get
        {
            return soundValue;
        }
        set
        {
            soundValue = value;
            currSfx.volume = value;
        }
    }


    public void PlayMusic(int m_index)
    {
        if (m_index >= 0 && m_index < musics.Length)
        {
            currBgm.clip = musics[m_index];
            currBgm.Play();
        }
    }

    public void StopMusic()
    {
        currBgm.Stop();
    }

    public void PlaySound(int s_index, AudioSource audioSource = null)
    {
        if (audioSource != null)
        {
            if (s_index >= 0 && s_index < sounds.Length && Vector3.Distance(PlayerManager.Instance.Player.transform.position, audioSource.transform.position) < 20)
            {
                audioSource.volume = soundValue;
                audioSource.PlayOneShot(sounds[s_index]);
            }

        }
        else
        {
            if (s_index >= 0 && s_index < sounds.Length)
            {
                currSfx.clip = sounds[s_index];
                currSfx.PlayOneShot(currSfx.clip);
            }
        }

    }

    public void StopSound() 
    {
        currSfx.Stop();
    }

    public void SaveData(ref GameData _gameData)
    {
        _gameData.settingData.Clear();
        _gameData.settingData.Add("sound",soundValue);
        _gameData.settingData.Add("music",musicValue);

    }

    public void LoadData(GameData _gameData)
    {
        _gameData.settingData.TryGetValue("sound", out soundValue);
        _gameData.settingData.TryGetValue("music", out musicValue);
        currBgm.volume = musicValue;
        currSfx.volume = soundValue;
    }
}
